<#include "public.ftl">
package ${basePackage};

import com.huitu.api.rest.AbstractApiResource;
import com.huitu.commons.PageUtils;
import com.huitu.whht.framework.jersey.utils.ApiResultBuilder;
import com.huitu.whht.hbszy.wrem.common.annotations.SzyWremApiResource;
import com.huitu.whht.hbszy.wrem.common.annotations.SzyWremApiService;
import com.huitu.whht.framework.common.factory.StatusRespBuilder;
<#list pkList as pk><#if (pk.javaType == 'Date')>import com.huitu.whht.framework.common.utils.LocalDateTimeUtil;
import java.time.LocalDateTime;<#break></#if></#list>
import ${basePackage}.entities.${baseClassName};
<#if (pkList?size>1)>import ${basePackage}.entities.${baseClassName}Key;</#if>
import ${basePackage}.entities.${baseClassName}Qo;
import ${basePackage}.service.I${baseClassName}${props.classNameSuffix}Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

/**
 * 说明: ${tab.remarks}API,表名称: ${tab.tableName} <br/>
 * 日期: ${currentDate}
 * @author ${author}
 */
@Component
@SzyWremApiResource
@Path("${path}")
public class ${baseClassName}${props.classNameSuffix}Resource extends AbstractApiResource {

    private static final Logger LOGGER = LoggerFactory.getLogger(${baseClassName}${props.classNameSuffix}Resource.class);

    private static final String UUID = "${uuid}";

    @Override
    public String getUUID() {
        return UUID;
    }

    @Autowired
    @SzyWremApiService
    I${baseClassName}${props.classNameSuffix}Service ${baseInstanceName}${props.classNameSuffix}Service;

    /**
     * @api {get} ${path}/<@pkPath pkList=pkList funcs=funcs></@pkPath> [R][G]根据主键查询
     * @apiDescription [G]根据主键查询${tab.tableName}(${tab.remarks})数据
     * @apiName (generate)select by primary key
     * @apiGroup ${apiGroup}-${tab.remarks}
     * @apiVersion 1.0.0
     * @apiSampleRequest <@pkSampleRequest path=path pkList=pkList funcs=funcs sampleData=sampleData></@pkSampleRequest>
<#list pkList as pk>
     * @apiParam   ${funcs.StringUtils.rightPad("{"+pk.javaType+"}",16)} ${funcs.StringUtils.rightPad(pk.entityProName,18)} 【必须】${pk.remarks}<#if col.javaType=='Date'>(时间格式 <font color='red'>yyyy-MM-dd HH:mm:ss</font>)</#if>
</#list>
<#list colList as col>
     * @apiSuccess ${funcs.StringUtils.rightPad("{"+col.javaType+"}",16)} ${funcs.StringUtils.rightPad(col.entityProName,18)} ${col.remarks}<#if col.javaType=='Date'>(时间格式 <font color='red'>yyyy-MM-dd HH:mm:ss</font>)</#if>
</#list>
     * @apiSuccessExample 请求成功:
     * HTTP/1.1 200 OK
     * {
     * "result": {
<#list colList as col>
     * "${col.entityProName}": ${funcs.DbDocUtil.getApiSuccessValue(col.javaType,col.entityProName,sampleData)}<#if col_has_next>,</#if>
</#list>
     *  }
     * }
     * @apiUse exceptions
     */
    @GET
    @Path("<@pkPath pkList=pkList funcs=funcs></@pkPath>")
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response selectByPrimaryKey(<@pkPathParams pkList=pkList funcs=funcs></@pkPathParams>) {
        <#if (pkList?size>1)>
        ${baseClassName}Key pk = new ${baseClassName}Key();
        <@invokePKProSetter pkList=pkList funcs=funcs objectName="pk"></@invokePKProSetter>
        </#if>
        LOGGER.info("根据主键查询 ${tab.remarks},参数 <#if (pkList?size>1)>pk<#else>${pkList[0].entityProName}</#if>:{}", <#if (pkList?size>1)>pk<#else>${pkList[0].entityProName}</#if>);
        return Response.ok(ApiResultBuilder.create(this, ${baseInstanceName}${props.classNameSuffix}Service.selectByPrimaryKey(<@serviceMethodPKParamValues pkList=pkList funcs=funcs baseInstanceName=baseInstanceName objectName="pk"></@serviceMethodPKParamValues>))).build();
    }

    /**
     * @api {post} ${path}/list [R][G]根据条件查询
     * @apiDescription [G]根据条件查询${tab.tableName}(${tab.remarks})数据
     * @apiName (generate)select by filter
     * @apiGroup ${apiGroup}-${tab.remarks}
     * @apiVersion 1.0.0
     * @apiSampleRequest ${path}/list
<#list qoList as qo>
     * @apiParam   ${funcs.StringUtils.rightPad("{"+qo.javaType+"}",16)?replace("<","(")?replace(">",")")} ${funcs.StringUtils.rightPad(qo.entityProName,18)} ${qo.remarks}
</#list>
<#list colList as col>
     * @apiSuccess ${funcs.StringUtils.rightPad("{"+col.javaType+"}",16)} ${funcs.StringUtils.rightPad(col.entityProName,18)} ${col.remarks}
</#list>
     * @apiSuccessExample 请求成功:
     * HTTP/1.1 200 OK
     * {
     * "result": [{
<#list colList as col>
     * "${col.entityProName}": ${funcs.DbDocUtil.getApiSuccessValue(col.javaType,col.entityProName,sampleData)}<#if col_has_next>,</#if>
</#list>
     *  }]
     * }
     *
     * @apiSuccessExample 分页请求:
     * request header: Rang={max=50;size=50;field=TS DESC}
     * HTTP/1.1 200 OK
     * {
     * "result": [{
<#list colList as col>
     * "${col.entityProName}": ${funcs.DbDocUtil.getApiSuccessValue(col.javaType,col.entityProName,sampleData)}<#if col_has_next>,</#if>
</#list>
     *  }],
     * "paging": {
     * "count": 3,
     * "total": 120,
     * "finale": false,
     * "index": 1
     * }
     * }
     * @apiUse header_rang
     * @apiUse exceptions
     */
    @POST
    @Path("list")
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response selectList(${baseClassName}Qo filter) {
        PageUtils.startPageFromRang();
        LOGGER.info("根据条件查询 ${tab.remarks},参数 ${baseClassName}Qo:{}", filter);
        return Response.ok(ApiResultBuilder.create(this, ${baseInstanceName}${props.classNameSuffix}Service.selectList(filter))).build();
    }

<#if props.partition??>
    /**
     * @api {post} ${path}/latest [R][G]最新监测数据
     * @apiDescription [G]根据条件查询${tab.tableName}(${tab.remarks})最新监测数据
     * @apiName (generate)select latest data by filter
     * @apiGroup ${apiGroup}-${tab.remarks}
     * @apiVersion 1.0.0
     * @apiSampleRequest ${path}/latest
    <#list qoList as qo>
     * @apiParam   ${funcs.StringUtils.rightPad("{"+qo.javaType+"}",16)?replace("<","(")?replace(">",")")} ${funcs.StringUtils.rightPad(qo.entityProName,18)} ${qo.remarks}<#if qo.javaType=='Date'>(时间格式 <font color='red'>yyyy-MM-dd HH:mm:ss</font>)</#if>
    </#list>
    <#list colList as col>
     * @apiSuccess ${funcs.StringUtils.rightPad("{"+col.javaType+"}",16)} ${funcs.StringUtils.rightPad(col.entityProName,18)} ${col.remarks}
    </#list>
     * @apiSuccessExample 请求成功:
     * HTTP/1.1 200 OK
     * {
     * "result": [{
    <#list colList as col>
     * "${col.entityProName}": ${funcs.DbDocUtil.getApiSuccessValue(col.javaType,col.entityProName,sampleData)}<#if col_has_next>,</#if>
    </#list>
     *  }]
     * }
     *
     * @apiSuccessExample 分页请求:
     * request header: Rang={max=50;size=50;field=TS DESC}
     * HTTP/1.1 200 OK
     * {
     * "result": [{
    <#list colList as col>
     * "${col.entityProName}": ${funcs.DbDocUtil.getApiSuccessValue(col.javaType,col.entityProName,sampleData)}<#if col_has_next>,</#if>
    </#list>
     *  }],
     * "paging": {
     * "count": 3,
     * "total": 120,
     * "finale": false,
     * "index": 1
     * }
     * }
     * @apiUse header_rang
     * @apiUse exceptions
     */
    @POST
    @Path("latest")
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response selectLatest(${baseClassName}Qo filter) {
        PageUtils.startPageFromRang();
        LOGGER.info("根据条件查询 ${tab.remarks} 最新监测数据,参数 ${baseClassName}Qo:{}", filter);
        return Response.ok(ApiResultBuilder.create(this, ${baseInstanceName}${props.classNameSuffix}Service.selectLatest(filter))).build();
    }
</#if>

    /**
     * @api {put} ${path} [C][G]新增数据
     * @apiPrivate
     * @apiDescription [G]新增${tab.tableName}(${tab.remarks})数据
     * @apiName (generate)add data
     * @apiGroup ${apiGroup}-${tab.remarks}
     * @apiVersion 1.0.0
<#list colList as col>
     * @apiParam   ${funcs.StringUtils.rightPad("{"+col.javaType+"}",16)} ${funcs.StringUtils.rightPad(col.entityProName,18)} <#if (col.nullable == 0 && col.columnName != 'TS')>【必须】</#if>${col.remarks}<#if col.javaType=='Date'>(时间格式 <font color='red'>yyyy-MM-dd HH:mm:ss</font>)</#if>
</#list>
     * @apiSuccess ${funcs.StringUtils.rightPad("{Integer}",16)} ${funcs.StringUtils.rightPad("status",18)} 1:新增成功;0:新增失败.
     * @apiSuccess ${funcs.StringUtils.rightPad("{String}",16)} ${funcs.StringUtils.rightPad("message",18)} 成功/失败消息内容
     * @apiSuccess ${funcs.StringUtils.rightPad("{Object}",16)} ${funcs.StringUtils.rightPad("data",18)} 额外返回的数据,通常包含新增数据的主键值
     * @apiSampleRequest ${path}
     * @apiSuccessExample 新增成功:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":1,
     * "message":"成功",
     * "data":{
<#list pkList as pk>
     *   "${pk.entityProName}": ${funcs.DbDocUtil.getApiSuccessValue(pk.javaType,pk.entityProName,sampleData)}<#if pk_has_next>,</#if>
</#list>
     *      }
     *   }
     * }
     @apiSuccessExample 新增失败:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":0,
     * "message":"失败",
     * "data":{
<#list pkList as pk>
     *   "${pk.entityProName}": ${funcs.DbDocUtil.getApiSuccessValue(pk.javaType,pk.entityProName,sampleData)}<#if pk_has_next>,</#if>
</#list>
     *      }
     *   }
     * }
     * @apiParamExample {json} 请求示例:
     * {
<#list colList as col>
     * "${col.entityProName}": ${funcs.DbDocUtil.getApiSuccessValue(col.javaType,col.entityProName,sampleData)}<#if col_has_next>,</#if>
</#list>
     * }
     * @apiUse exceptions
     */
    @PUT
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response insert(${baseClassName} record) {
        LOGGER.info("新增 ${tab.remarks},参数 ${baseClassName}:{}", record);
        return Response.ok(ApiResultBuilder.create(this, StatusRespBuilder.insert(${baseInstanceName}${props.classNameSuffix}Service.insertSelective(record),record))).build();
    }

    /**
     * @api {put} ${path}/<@pkPath pkList=pkList funcs=funcs></@pkPath>/update [U][G]根据主键修改
     * @apiPrivate
     * @apiDescription [G]根据主键修改${tab.tableName}(${tab.remarks})数据
     * @apiName (generate)update data
     * @apiGroup ${apiGroup}-${tab.remarks}
     * @apiVersion 1.0.0
<#list colList as col>
     * @apiParam   ${funcs.StringUtils.rightPad("{"+col.javaType+"}",16)} ${funcs.StringUtils.rightPad(col.entityProName,18)} <#if col.nullable == 0>【必须】</#if>${col.remarks}
</#list>
     * @apiSuccess ${funcs.StringUtils.rightPad("{Integer}",16)} ${funcs.StringUtils.rightPad("status",18)} 1:修改成功;0:要修改的数据不存在(可能已被删除)
     * @apiSuccess ${funcs.StringUtils.rightPad("{String}",16)} ${funcs.StringUtils.rightPad("message",18)} 成功/失败消息内容
     * @apiSuccess ${funcs.StringUtils.rightPad("{Object}",16)} ${funcs.StringUtils.rightPad("data",18)} 额外返回的数据
     * @apiSampleRequest <@pkSampleRequest path=path pkList=pkList funcs=funcs sampleData=sampleData></@pkSampleRequest>/update
     * @apiSuccessExample 修改成功:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":1,
     * "message":"成功",
     * "data":null
     *   }
     * }
     * @apiSuccessExample 修改失败:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":0,
     * "message":"失败",
     * "data":null
     *   }
     * }
     * @apiParamExample {json} 请求示例:
     * {
<#list colList as col>
     * "${col.entityProName}": ${funcs.DbDocUtil.getApiSuccessValue(col.javaType,col.entityProName,sampleData)}<#if col_has_next>,</#if>
</#list>
     * }
     * @apiUse exceptions
     */
    @PUT
    @Path("<@pkPath pkList=pkList funcs=funcs></@pkPath>/update")
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response update(<@pkPathParams pkList=pkList funcs=funcs></@pkPathParams>, ${baseClassName} record) {
        <@invokePKProSetter pkList=pkList funcs=funcs objectName="record"></@invokePKProSetter>
        LOGGER.info("根据主键修改 ${tab.remarks},参数 ${baseClassName}:{}", record);
        return Response.ok(ApiResultBuilder.create(this, StatusRespBuilder.update(${baseInstanceName}${props.classNameSuffix}Service.updateByPrimaryKey(record)))).build();
    }

    /**
     * @api {put} ${path}/<@pkPath pkList=pkList funcs=funcs></@pkPath>/update-selective [U][G]根据主键修改(只修改非null字段)
     * @apiPrivate
     * @apiDescription [G]根据主键修改${tab.tableName}(${tab.remarks})数据,只修改非null字段
     * @apiName (generate)update selected data
     * @apiGroup ${apiGroup}-${tab.remarks}
     * @apiVersion 1.0.0
<#list colList as col>
     * @apiParam   ${funcs.StringUtils.rightPad("{"+col.javaType+"}",16)} ${funcs.StringUtils.rightPad(col.entityProName,18)} ${col.remarks}
</#list>
     * @apiSuccess ${funcs.StringUtils.rightPad("{Integer}",16)} ${funcs.StringUtils.rightPad("status",18)} 1:修改成功;0:要修改的数据不存在(可能已被删除)
     * @apiSuccess ${funcs.StringUtils.rightPad("{String}",16)} ${funcs.StringUtils.rightPad("message",18)} 成功/失败消息内容
     * @apiSuccess ${funcs.StringUtils.rightPad("{Object}",16)} ${funcs.StringUtils.rightPad("data",18)} 额外返回的数据
     * @apiSampleRequest <@pkSampleRequest path=path pkList=pkList funcs=funcs sampleData=sampleData></@pkSampleRequest>/update-selective
     * * @apiSuccessExample 修改成功:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":1,
     * "message":"成功",
     * "data":null
     *   }
     * }
     * @apiSuccessExample 修改失败:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":0,
     * "message":"失败",
     * "data":null
     *   }
     * }
     * @apiParamExample {json} 请求示例:
     * {
<#list colList as col>
     * "${col.entityProName}": ${funcs.DbDocUtil.getApiSuccessValue(col.javaType,col.entityProName,sampleData)}<#if col_has_next>,</#if>
</#list>
     * }
     * @apiUse exceptions
     */
    @PUT
    @Path("<@pkPath pkList=pkList funcs=funcs></@pkPath>/update-selective")
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response updateSelective(<@pkPathParams pkList=pkList funcs=funcs></@pkPathParams>, ${baseClassName} record) {
        <@invokePKProSetter pkList=pkList funcs=funcs objectName="record"></@invokePKProSetter>
        LOGGER.info("根据主键修改(只修改非null字段) ${tab.remarks},参数 ${baseClassName}:{}", record);
        return Response.ok(ApiResultBuilder.create(this, StatusRespBuilder.update(${baseInstanceName}${props.classNameSuffix}Service.updateByPrimaryKeySelective(record)))).build();
    }

    /**
     * @api {delete} ${path}/<@pkPath pkList=pkList funcs=funcs></@pkPath> [D][G]根据主键删除
     * @apiPrivate
     * @apiDescription [G]根据主键删除${tab.tableName}(${tab.remarks})数据
     * @apiName (generate)delete by primary key
     * @apiGroup ${apiGroup}-${tab.remarks}
     * @apiVersion 1.0.0
     * @apiSampleRequest <@pkSampleRequest path=path pkList=pkList funcs=funcs sampleData=sampleData></@pkSampleRequest>
<#list pkList as pk>
     * @apiParam   ${funcs.StringUtils.rightPad("{"+pk.javaType+"}",16)} ${funcs.StringUtils.rightPad(pk.entityProName,18)} 【必须】${pk.remarks}
</#list>
     * @apiSuccess ${funcs.StringUtils.rightPad("{Integer}",16)} ${funcs.StringUtils.rightPad("status",18)} 1:删除成功;0:要删除的数据不存在(可能已被删除).
     * @apiSuccess ${funcs.StringUtils.rightPad("{String}",16)} ${funcs.StringUtils.rightPad("message",18)} 成功/失败消息内容
     * @apiSuccess ${funcs.StringUtils.rightPad("{Object}",16)} ${funcs.StringUtils.rightPad("data",18)} 额外返回的数据
     * @apiSuccessExample 删除成功:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":1,
     * "message":"成功",
     * "data":null
     *   }
     * }
     * @apiSuccessExample 删除失败:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":0,
     * "message":"失败",
     * "data":null
     *   }
     * }
     * @apiUse exceptions
     */
    @DELETE
    @Path("<@pkPath pkList=pkList funcs=funcs></@pkPath>")
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response delete(<@pkPathParams pkList=pkList funcs=funcs></@pkPathParams>) {
        <#if (pkList?size>1)>
         ${baseClassName}Key pk = new ${baseClassName}Key();
         <@invokePKProSetter pkList=pkList funcs=funcs objectName="pk"></@invokePKProSetter>
        </#if>
        LOGGER.info("根据主键删除 ${tab.remarks},参数 <#if (pkList?size>1)>pk<#else>${pkList[0].entityProName}</#if>:{}", <#if (pkList?size>1)>pk<#else>${pkList[0].entityProName}</#if>);
        Integer rows = ${baseInstanceName}${props.classNameSuffix}Service.deleteByPrimaryKey(<#if (pkList?size>1)>pk<#else>${pkList[0].entityProName}</#if>);
        return Response.ok(ApiResultBuilder.create(this, StatusRespBuilder.delete(rows))).build();
    }

    /**
     * @api {delete} ${path}/by-filter [D][G]根据条件删除
     * @apiPrivate
     * @apiDescription [G]根据条件删除${tab.tableName}(${tab.remarks})数据
     * @apiName (generate)delete by filter
     * @apiGroup ${apiGroup}-${tab.remarks}
     * @apiVersion 1.0.0
     * @apiSampleRequest ${path}/by-filter
<#list qoList as qo>
     * @apiParam   ${funcs.StringUtils.rightPad("{"+qo.javaType+"}",16)?replace("<","(")?replace(">",")")} ${funcs.StringUtils.rightPad(qo.entityProName,18)} ${qo.remarks}
</#list>
     * @apiSuccess ${funcs.StringUtils.rightPad("{Integer}",16)} ${funcs.StringUtils.rightPad("status",18)} 通常1或者>1:删除成功;0:没有符合条件的数据.
     * @apiSuccess ${funcs.StringUtils.rightPad("{String}",16)} ${funcs.StringUtils.rightPad("message",18)} 成功/失败消息内容
     * @apiSuccess ${funcs.StringUtils.rightPad("{Object}",16)} ${funcs.StringUtils.rightPad("data",18)} 额外返回的数据
     * @apiSuccessExample 删除成功:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":1,
     * "message":"成功",
     * "data":null
     *   }
     * }
     * @apiSuccessExample 删除失败:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":0,
     * "message":"失败",
     * "data":null
     *   }
     * }
     * @apiUse exceptions
     */
    @DELETE
    @Path("by-filter")
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response deleteByFilter(${baseClassName}Qo filter) {
        LOGGER.info("根据条件删除 ${tab.remarks},参数 ${baseClassName}Qo:{}", filter);
        Integer rows = ${baseInstanceName}${props.classNameSuffix}Service.deleteByFilter(filter);
        return Response.ok(ApiResultBuilder.create(this, StatusRespBuilder.delete(rows))).build();
    }
}
